function isNullOrEmpty(val) {
    return val == ""
        || val == null || val == undefined;
}

function initPage(title, tabName) {
    document.title = title;
    $(".foot-item."+tabName).addClass("active");
}

function indexPage() {
    window.location.href = "/wechat";
}
function orderPage() {
    window.location.href = "/wechat/order/otherOrder";
}
function rankPage() {
    window.location.href = "/wechat/rank";
}
function centerPage() {
    window.location.href = "/wechat/userCenter";
}

function getTimeGap(from, arr, returnType) {

    var fromTime = new Date();
    var toTime;
    var ua = navigator.userAgent.toLowerCase(); 
    if (/iphone|ipad|ipod/.test(ua)) {
        toTime = new Date(arr[0],arr[1]-1,arr[2],arr[3],arr[4],arr[5]);      
    } else if (/android/.test(ua)) {
        toTime = new Date(arr); 
    }

    var LeftTime = parseInt((toTime.getTime() - fromTime.getTime())/1000);
    if (LeftTime <= 0) {
        return false;
    };

    var returnArray = [];

    // switch (returnType) {

    //     case returnType == "days":
    //         returnArray["days"] = Math.floor(LeftTime/(60*60*24));
    //         returnArray["hours"] = pad(Math.floor(LeftTime/(60*60)%24),2);
    //         returnArray["minutes"] = pad(Math.floor(LeftTime/60%60),2);
    //         returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    //         break;
    //     case returnType == "hours":
    //         returnArray["hours"] = pad(Math.floor(LeftTime/(60*60)),2);
    //         returnArray["minutes"] = pad(Math.floor(LeftTime/60%60),2);
    //         returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    //         break;
    //     case returnType == "minutes":
    //         returnArray["minutes"] = pad(Math.floor(LeftTime/60),2);
    //         returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    //         break;
    //     case returnType == "seconds":
    //         returnArray["seconds"] = pad(Math.floor(LeftTime),2);
    //         break;
    //     default :
    //         returnArray["days"] = pad(Math.floor(LeftTime/(60*60*24)),2);
    //         returnArray["hours"] = pad(Math.floor(LeftTime/(60*60)%24),2);
    //         returnArray["minutes"] = pad(Math.floor(LeftTime/60%60),2);
    //         returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    //         break;

    // }

    if (returnType == "days") {
        returnArray["days"] = Math.floor(LeftTime/(60*60*24));
        returnArray["hours"] = pad(Math.floor(LeftTime/(60*60)%24),2);
        returnArray["minutes"] = pad(Math.floor(LeftTime/60%60),2);
        returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    }else if(returnType == "hours"){
        returnArray["hours"] = pad(Math.floor(LeftTime/(60*60)),2);
        returnArray["minutes"] = pad(Math.floor(LeftTime/60%60),2);
        returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    }else if(returnType == "minutes"){
        returnArray["minutes"] = pad(Math.floor(LeftTime/60),2);
        returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    }else if(returnType == "seconds"){
        returnArray["seconds"] = pad(Math.floor(LeftTime),2);

    }

    return returnArray;

}

function getTimeGap2(from, to, returnType) {

    var fromTime;
    var toTime = to;
    var ua = navigator.userAgent.toLowerCase(); 
    if (/iphone|ipad|ipod/.test(ua)) {
        fromTime = new Date(from[0],from[1]-1,from[2],from[3],from[4],from[5]);    
    } else if (/android/.test(ua)) {
        fromTime = new Date(from);
    }

    var LeftTime = parseInt((toTime.getTime() - fromTime.getTime())/1000);
    console.log(fromTime);
    if (LeftTime <= 0) {
        return false;
    };

    var returnArray = [];

    // switch (returnType) {

    //     case returnType == "days":
    //         returnArray["days"] = Math.floor(LeftTime/(60*60*24));
    //         returnArray["hours"] = pad(Math.floor(LeftTime/(60*60)%24),2);
    //         returnArray["minutes"] = pad(Math.floor(LeftTime/60%60),2);
    //         returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    //         break;
    //     case returnType == "hours":
    //         returnArray["hours"] = pad(Math.floor(LeftTime/(60*60)),2);
    //         returnArray["minutes"] = pad(Math.floor(LeftTime/60%60),2);
    //         returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    //         break;
    //     case returnType == "minutes":
    //         returnArray["minutes"] = pad(Math.floor(LeftTime/60),2);
    //         returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    //         break;
    //     case returnType == "seconds":
    //         returnArray["seconds"] = pad(Math.floor(LeftTime),2);
    //         break;
    //     default :
    //         returnArray["days"] = pad(Math.floor(LeftTime/(60*60*24)),2);
    //         returnArray["hours"] = pad(Math.floor(LeftTime/(60*60)%24),2);
    //         returnArray["minutes"] = pad(Math.floor(LeftTime/60%60),2);
    //         returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    //         break;

    // }

    if (returnType == "days") {
        returnArray["days"] = Math.floor(LeftTime/(60*60*24));
        returnArray["hours"] = pad(Math.floor(LeftTime/(60*60)%24),2);
        returnArray["minutes"] = pad(Math.floor(LeftTime/60%60),2);
        returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    }else if(returnType == "hours"){
        returnArray["hours"] = pad(Math.floor(LeftTime/(60*60)),2);
        returnArray["minutes"] = pad(Math.floor(LeftTime/60%60),2);
        returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    }else if(returnType == "minutes"){
        returnArray["minutes"] = pad(Math.floor(LeftTime/60),2);
        returnArray["seconds"] = pad(Math.floor(LeftTime%60),2);
    }else if(returnType == "seconds"){
        returnArray["seconds"] = pad(Math.floor(LeftTime),2);

    }

    return returnArray;

}

function pad(num, n) {
    var len = num.toString().length;
    while(len < n) {
        num = "0" + num;
        len++;
    }
    return num;
}

function safariDate(endtime){
    var d = endtime.replace(/[-\s\:]/g,',');
    var arr = [];
    arr = d.split(",");
    return arr;
}